﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _27_DDD.Models
{
    public class User
    {
        public int Id { get; init; }
        public DateTime CreateDateTime { get; init; }
        public string UserName { get; private set; }

        public int Credits { get; set; }

        private string? PasswordHash;

        private string? remark;
        public string? Remark
        {
            get
            {
                return remark;
            }
        }

        // public string? Remark { get; set; }



        public string? Tag { get; set; }

        private User() { } // 给EFCore从数据库加载对象用

        public User(string yhm)
        {
            this.UserName = yhm;
            this.CreateDateTime = DateTime.Now;
            this.Credits = 10;
        }

        public void ChangeUserName(string un)
        {
            if (un.Length < 5)
            {
                Console.WriteLine("用户名长度太短");
                return;

            }
            this.UserName = un;
        }
        public void ChangePassword(string pwd)
        {
            if (pwd.Length < 3)
            {
                Console.WriteLine("密码长度不能小于3");
                return;
            }
            this.PasswordHash = HashHelper.GetMd5Hash(pwd);
        }

    }
}
